package com.lxx.train.business.controller.admin;

import com.lxx.train.common.resp.CommonResp;
import com.lxx.train.common.resp.PageResp;
import com.lxx.train.business.req.TrainCarriageQueryReq;
import com.lxx.train.business.req.TrainCarriageSaveReq;
import com.lxx.train.business.resp.TrainCarriageQueryResp;
import com.lxx.train.business.service.TrainCarriageService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/train-carriage")
public class TrainCarriageAdminController {

    @Autowired
    private TrainCarriageService trainCarriageService;

    // 新增 / 更新
    // 判断前端有无传id，没有则是新增，否则是更新
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody TrainCarriageSaveReq req) {
        trainCarriageService.save(req);
        return CommonResp.ok();
    }

    // 查询列表
    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainCarriageQueryResp>> queryList(@Valid TrainCarriageQueryReq req) {
        PageResp<TrainCarriageQueryResp> pageResp = trainCarriageService.queryList(req);
        return CommonResp.ok(pageResp);
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        trainCarriageService.delete(id);
        return CommonResp.ok();
    }

}
